package com.clayecloud.module_main.entity;

import android.widget.ImageView;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;


public class News extends BaseObservable {

    private String title;

    private String content_excerpt;

    private String cover_photo;

    public News(String title, String content_excerpt, String cover_photo) {
        this.title = title;
        this.content_excerpt = content_excerpt;
        this.cover_photo = cover_photo;
    }

    @Bindable
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Bindable
    public String getContent_excerpt() {
        return content_excerpt;
    }

    public void setContent_excerpt(String content_excerpt) {
        this.content_excerpt = content_excerpt;
    }

    public String getCover_photo() {
        return cover_photo;
    }

    public void setCover_photo(String cover_photo) {
        this.cover_photo = cover_photo;
    }

    @BindingAdapter({"coverPhoto"})
    public static void getCoverPhoto(ImageView view, String cover_photo){
        RoundedCorners roundedCorners = new RoundedCorners(25);
        //通过RequestOptions扩展功能,override:采样率,因为ImageView就这么大,可以压缩图片,降低内存消耗
        // RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300);
        RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
        Glide.with(view.getContext()).load(cover_photo).apply(options).into((ImageView) view);
    }

}
